home *** CD-ROM | disk | FTP | other *** search
/ Enter 2006 February / enter-2006-02.iso / files / Illustrator_CS2_ue_TryOut.exe / bridge / Adobe Bridge 1.0.msi / Data1.cab / _5breakpointsPane.jsx < prev    next >
Encoding:
Text File  |  2005-03-24  |  11.2 KB  |  352 lines

  1. /**************************************************************************
  2. *
  3. *  @@@BUILDINFO@@@ 35breakpointsPane.jsx 1.0.0.47 07-Feb-2005
  4. *  Copyright 2005 Adobe Systems Incorporated
  5. *  All Rights Reserved.
  6. *
  7. * NOTICE:  All information contained herein is, and remains the property of
  8. * Adobe Systems Incorporated  and its suppliers,  if any.  The intellectual 
  9. * and technical concepts contained herein are proprietary to  Adobe Systems 
  10. * Incorporated  and its suppliers  and may be  covered by U.S.  and Foreign 
  11. * Patents,patents in process,and are protected by trade secret or copyright 
  12. * law.  Dissemination of this  information or reproduction of this material
  13. * is strictly  forbidden  unless prior written permission is  obtained from 
  14. * Adobe Systems Incorporated.
  15. **************************************************************************/
  16.  
  17. // Code to add to the Breakpoints pane
  18. // window.breakpoints is a LiveObject. We add methods to it which can
  19. // be invoked from C++ as well as scripts
  20.  
  21. // Global properties used:
  22. //    window: LiveObject representing the main window
  23. //    document: LiveObject representing the currently active document (script)
  24.  
  25. // When a breakpoints list item is selected, highlight the script line it
  26. // refers to
  27.  
  28. window.breakpoints.list.onChange = function ()
  29. {
  30.     if (this.selection != null && document != null) {
  31.         document.setSelection (document.lineToOffset (this.selection.bpInfo.line));
  32.     }
  33. } // onChange
  34.  
  35.  
  36. // When a breakpoints list item is double-clicked, show the Change Breakpoint
  37. // dialog for the breakpoint it refers to
  38.  
  39. window.breakpoints.list.onDoubleClick = function ()
  40. {
  41.     if (this.selection != null) {
  42.         this.parent.changeBP ();
  43.     }
  44. } // onDoubleClick
  45.  
  46.  
  47. // update()
  48. // update the contents of the BreakpointsPane for the current script
  49.  
  50. window.breakpoints.update = function ()
  51. {
  52.     // start clean
  53.     this.invalidate();
  54.  
  55.     //    Get the current script (document)
  56.     if (document == undefined || document == null)
  57.         return;
  58.     var script = document;
  59.  
  60.     //    Get all the BPs for the current script and add them to the list
  61.     var bpsList = script.getAllBP();
  62.     var numBPs = bpsList.length;
  63.     for (bpIdx = 0; bpIdx < numBPs; bpIdx++) {
  64.         var bpInfo = bpsList[bpIdx];
  65.         var hasCondition = (bpInfo.condition != undefined);
  66.         var line = bpInfo.line + 1;
  67.         var text = localize ("$$$/ESToolkit/Panes/Breakpoints/List/Line= Line %1", line);
  68.         if (hasCondition)
  69.             text += localize ("$$$/ESToolkit/Panes/Breakpoints/List/When= when (%1)", bpInfo.condition);
  70.         var bpItem = this.list.add ('item', text);
  71.         bpItem.icon = (bpInfo.enabled ?
  72.                         (hasCondition ? "BreakpointEnabledCond" : "BreakpointEnabled" )
  73.                         :
  74.                         (hasCondition ? "BreakpointDisabledCond" : "BreakpointDisabled"));
  75.         //    Remember the BP info so it can be accessed when this list item is selected
  76.         bpItem.bpInfo = bpInfo;
  77.     }
  78. } // update
  79.  
  80.  
  81. // invalidate() is called when the current script is closed or deactivated
  82.  
  83. window.breakpoints.invalidate = function ()
  84. {
  85.     //    Erase the current BPs list
  86.     this.list.selection = null;
  87.     this.list.removeAll();
  88. } // invalidate
  89.  
  90.  
  91. // bool canAddBP()
  92. // Return true if a new breakpoint can be created (i.e., there is a current script)
  93.  
  94. window.breakpoints.canAddBP = function ()
  95. {
  96.     return (document != undefined && document != null);
  97. } // canAddBP
  98.  
  99.  
  100. // bool canChangeBP()
  101. // Return true if a breakpoint is selected and can be modified
  102.  
  103. window.breakpoints.canChangeBP = function ()
  104. {
  105.     return this.list.selection != null;
  106. } // canChangeBP
  107.  
  108.  
  109. // bool canRemoveBP()
  110. // Return true if a breakpoint is selected and can be removed
  111.  
  112. window.breakpoints.canRemoveBP = function ()
  113. {
  114.     return this.list.selection != null;
  115. } // canRemoveBP
  116.  
  117.  
  118. // bool addBP()
  119. // Show a dialog to add a new breakpoint to the current script
  120.  
  121. window.breakpoints.addBP = function ()
  122. {
  123.     //    Create a dialog for defining a new breakpoint
  124.     var dlg = new Window (this.addChangeDlg.resourceSpec);
  125.     dlg.text = localize("$$$/ESToolkit/AddChangeBPDlg/titleAddBP=Add Breakpoint");
  126.     
  127.     //    Initial state
  128.     dlg.body.props.le.enabledCb.value = true;
  129.  
  130.     //    Define event handlers
  131.     dlg.onShow = this.addChangeDlg.onShow;
  132.     dlg.onClose = this.addChangeDlg.onClose;
  133.     dlg.btns.ok.onClick = this.addChangeDlg.btnOnClick;
  134.     dlg.btns.cancel.onClick = this.addChangeDlg.btnOnClick;
  135.     //    Don't want the 'Remove' button for the Add dialog
  136.     dlg.btns.remove (dlg.btns.removeBP);
  137.  
  138.     dlg.center();
  139.     if (dlg.show() == 1) {
  140.         // Define a new BP
  141.         with (dlg.body.props) {
  142.             var line = le.line.text - 1;
  143.             var enabled = le.enabledCb.value != 0;
  144.             var cond = null;
  145.             if (condition.text.length > 0)
  146.                 cond = condition.text;
  147.             document.restoreBP (line, enabled, cond);
  148.         }
  149.         this.update();
  150.     }
  151. } // addBP
  152.  
  153.  
  154. // bool changeBP()
  155. // Show a dialog to add a new breakpoint to the current script
  156.  
  157. window.breakpoints.changeBP = function ()
  158. {
  159.     //    Create a dialog for editing the BP info
  160.     var dlg = new Window (this.addChangeDlg.resourceSpec);
  161.     dlg.text = localize ("$$$/ESToolkit/AddChangeBPDlg/titleChangeBP=Change Breakpoint");
  162.     
  163.     //    Initialize it with current BP info
  164.     var bpInfo = window.breakpoints.list.selection.bpInfo;
  165.     with (dlg.body.props.le) {
  166.         line.text = bpInfo.line + 1;
  167.         enabledCb.value = bpInfo.enabled;
  168.     }
  169.     dlg.body.props.condition.text = bpInfo.condition != undefined ? bpInfo.condition : "";
  170.  
  171.     dlg.onShow = this.addChangeDlg.onShow;
  172.     dlg.onClose = this.addChangeDlg.onClose;
  173.     dlg.btns.ok.onClick = this.addChangeDlg.btnOnClick;
  174.     dlg.btns.cancel.onClick = this.addChangeDlg.btnOnClick;
  175.     dlg.btns.removeBP.onClick = this.addChangeDlg.btnOnClick;
  176.  
  177.     dlg.center();
  178.     var action = dlg.show();
  179.     if (action == 1) {
  180.         // Change this breakpoint:
  181.         // delete the current one and create one with the new properties
  182.         document.clearBP (bpInfo.line);
  183.         with (dlg.body.props) {
  184.             var line = le.line.text - 1;
  185.             var enabled = le.enabledCb.value != 0;
  186.             var cond = null;
  187.             if (condition.text.length > 0)
  188.                 cond = condition.text;
  189.             document.restoreBP (line, enabled, cond);
  190.         }
  191.         this.update();
  192.     }
  193.     else if (action == 3) {
  194.         // Delete this breakpoint
  195.         document.clearBP (bpInfo.line);
  196.         this.update();
  197.     }
  198. } // changeBP
  199.  
  200.  
  201. // bool removeBP()
  202. // Show a dialog to add a new breakpoint to the current script
  203.  
  204. window.breakpoints.removeBP = function ()
  205. {
  206.     var line = this.list.selection.bpInfo.line;
  207.     document.clearBP (line);
  208.     this.update();
  209. } // removeBP
  210.  
  211. // void editBP()
  212. // Select and change a breakpoint at the given line. Used by the Editor context menu.
  213.  
  214. window.breakpoints.editBP = function (line)
  215. {
  216.     // find the BP
  217.     for (var i = 0; i < this.list.items.length; i++)
  218.     {
  219.         if (this.list.items [i].bpInfo.line == line)
  220.         {
  221.             this.list.selection = this.list.items [i];
  222.             this.changeBP();
  223.             break;
  224.         }
  225.     }
  226. }
  227.  
  228. //////////////////////////////////////////////////////////////////////
  229. // Dialog utility functions and resources
  230.  
  231. window.breakpoints.addChangeDlg = {
  232.  
  233. // an onShow event callback function for the add/change dialog.
  234. // It is used to adjust the position of text labels to align
  235. // with corresponding edit fields.
  236.  
  237. onShow: function ()
  238. {
  239.     //    Position labels in alignment with corresponding edit fields
  240.     with (this.body) {
  241.         labels.size.height = props.size.height;
  242.         var lineEditHt = props.le.line.size.height;
  243.         labels.line.location.y = props.le.location.y + ((lineEditHt - labels.line.size.height) / 2);
  244.         labels.condition.location.y = props.condition.location.y;
  245.     }
  246. }, // onShow
  247.  
  248. // an onClose event callback function for the add/change dialog.
  249. // It returns 'false' if the dialog was dismissed by the OK button and
  250. // any field contains an invalid value.
  251. onClose: function ()
  252. {
  253.     var ok = true;
  254.     if (this.okButtonClicked) {
  255.         /* Must validate the specified line number and any 'condition'
  256.            specified before allowing the dialog to close */
  257.         var lineNum = this.body.props.le.line.text;
  258.         ok = (lineNum >= 0) && (lineNum < document.lines.length);
  259.         if (! ok) {
  260.             errorBox ("$$$/ESToolkit/Alerts/LineNumberError=Line number out of range");
  261.         }
  262.         if (ok && this.body.props.condition.text.length > 0) {
  263.             var cond = this.body.props.condition.text;
  264.             if (cond.indexOf ('\n') >= 0 || cond.indexOf ('\r') >= 0) {
  265.                 /* newline characters or cr/nl pairs in the condition mess up evaluation
  266.                    and mess up display of the condition, so replace any line control chars with spaces */
  267.                 cond = cond.replace (/\r/g, ' ');
  268.                 cond = cond.replace (/\n/g, ' ');
  269.                 this.body.props.condition.text = cond;
  270.             }
  271.             // checkSyntax returns true, or an error message string
  272.             ok = Document.checkSyntax (this.body.props.condition.text);
  273.             if (ok != true) {
  274.                 errorBox ("$$$/ESToolkit/Alerts/ConditionSyntaxError=Syntax Error in condition: %1", ok);
  275.                 ok = false;    // don't close dialog yet
  276.             }
  277.         }
  278.         this.okButtonClicked = ok;
  279.     }
  280.     return ok;
  281. }, // onClose
  282.  
  283. // an onClick event callback for the OK/Cancel/Remove buttons in the add/change dialog
  284. btnOnClick: function ()
  285. {
  286.     var dlg = this.parent.parent;
  287.     if (this.properties.name == 'ok') {
  288.         //    OK button
  289.         dlg.okButtonClicked = true;
  290.         dlg.close(1);
  291.     }
  292.     else if (this.properties.name == 'cancel')
  293.         //    Cancel button
  294.         dlg.close(2);
  295.     else
  296.         //    Remove button
  297.         dlg.close(3);
  298. }, // btnOnClick
  299.  
  300. // Resource specification for the add/change dialog
  301. resourceSpec:
  302.     "dialog {                                                            \
  303.         orientation:'column', alignChildren:'left',                        \
  304.         body: Group {                                                    \
  305.             orientation:'row', alignChildren:'top',                        \
  306.             labels: Group {                                                \
  307.                 orientation:'column', alignChildren:'right',            \
  308.                 line:    StaticText {                                    \
  309.                     text:'$$$/ESToolkit/AddChangeBPDlg/Line=Line:'        \
  310.                 },                                                        \
  311.                 condition:    StaticText {                                \
  312.                     text:'$$$/ESToolkit/AddChangeBPDlg/Condition=Condition:'    \
  313.                 }                                                        \
  314.             },                                                            \
  315.             props: Group {                                                \
  316.                 orientation:'column', alignChildren:'left',                \
  317.                 le: Group {                                                \
  318.                     line:    EditText {                                    \
  319.                         preferredSize:[60,20], justify:'right',            \
  320.                         helpTip:'$$$/ESToolkit/AddChangeBPDlg/htLine=The line number for this breakpoint'    \
  321.                     },                                                    \
  322.                     enabledCb:    Checkbox {                                \
  323.                         text:'$$$/ESToolkit/AddChangeBPDlg/Enabled=&Enabled',    \
  324.                         helpTip:'$$$/ESToolkit/AddChangeBPDlg/htEnabled=Enable or disable this breakpoint'    \
  325.                     }                                                    \
  326.                 },                                                        \
  327.                 condition:    EditText {                                    \
  328.                     properties:{ multiline:true, scrolling:true },        \
  329.                     preferredSize:[300,40],                                \
  330.                         helpTip:'$$$/ESToolkit/AddChangeBPDlg/htCondition=Enter a JavaScript expression that should evaluate to true before a breakpoint is hit'    \
  331.                 }                                                        \
  332.             }                                                            \
  333.         },                                                                \
  334.         btns:    Group {                                                    \
  335.             alignment:'right',                                            \
  336.             removeBP:    Button {                                        \
  337.                 text:'$$$/ESToolkit/AddChangeBPDlg/Remove=&Remove',        \
  338.                 properties:{ name:'remove' }                            \
  339.             },                                                            \
  340.             gap: StaticText { size:[5,1] },                                \
  341.             ok:    Button {                                                \
  342.                 text:'$$$/CT/ExtendScript/UI/OK=OK',                    \
  343.                 properties:{ name:'ok' }                                \
  344.             },                                                            \
  345.             cancel:    Button {                                            \
  346.                 text:'$$$/CT/ExtendScript/UI/Cancel=Cancel',            \
  347.                 properties:{ name:'cancel' }                            \
  348.             }                                                            \
  349.         }                                                                \
  350.     }"
  351. };
  352.